#pragma once
#include "NctiTool.h"

#include <algorithm>

#include "dcl_ncti_pubfun.h"

namespace NCTI
{
    class NctiRubberbandScreenRect;
    class NctiRenderUnstructureItem;
    class NctiDisplayGridMesh;
    class NctiMeshBody;

    class DECL_NCTI_PUBFUN NctiToolMeshGridDo : public NctiTool
    {
        NCTI_TOOL_FUNCTIONS(NctiToolMeshGridDo)
    public:
        NctiToolMeshGridDo();
        void Inactivate()override;
        void ClearPreview();

        using CallbackFn = std::function<bool(NctiMeshBody*body, NctiSelectType stp,std::set<NctiGridPickSet>& prevCell)>;
        static void SetPreviewCallback(CallbackFn);

        bool on_cruise(NctiPosition st);
        bool on_drag(NctiPosition st, NctiPosition ed);
        bool on_pick(NctiPosition st, NctiPosition ed,int status);

    protected:
        void init_operator()override;
        EnumNctiResult ProcessContextMenu(EnumNctiMenuProcMode i_eProcMode) override;

    private:
        std::vector<NctiDisplayGridMesh*> currentGrid(std::vector<NctiRenderSegmentItem*>*ins=nullptr)const;
        NctiRenderSegmentItem* m_prevIns{ nullptr };
        NctiRenderUnstructureItem* m_prevLast{nullptr};
        std::set<NctiGridPickSet> m_prevCell;
        std::set<std::pair<NctiRenderUnstructureItem*,NctiRenderSegmentItem*>> m_last;
    };
}

